package com.hzit.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.struts2.ServletActionContext;
public class FileActionTest {
	private File file;
	private String fileContentType;
	private String fileFileName;
	public File getFile() {
		return file;
	}
	public void setFile(File file) {
		this.file = file;
	}
	public String getFileContentType() {
		return fileContentType;
	}
	public void setFileContentType(String fileContentType) {
		this.fileContentType = fileContentType;
	}
	public String getFileFileName() {
		return fileFileName;
	}
	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}
	
	public String upload(){
		String path=ServletActionContext.getRequest().getSession().getServletContext().getRealPath("")+"/file/"+fileFileName;
		try {
			OutputStream os=new FileOutputStream(path);
			InputStream is =new FileInputStream(file);
			int temp=0;
			while((temp=is.read())!=-1){
				os.write(temp);
			}
			os.close();
			is.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return  "upload";
	}
	
	private String contentType;
	private String contentDisposition;
	private long contentLength;
	private InputStream inputStream;
	public String getContentType() {
		return contentType;
	}
	public void setContentType(String contentType) {
		this.contentType = contentType;
	}
	public String getContentDisposition() {
		return contentDisposition;
	}
	public void setContentDisposition(String contentDisposition) {
		this.contentDisposition = contentDisposition;
	}
	public long getContentLength() {
		return contentLength;
	}
	public void setContentLength(long contentLength) {
		this.contentLength = contentLength;
	}
	public InputStream getInputStream() {
		return inputStream;
	}
	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}
	public String download(){
		contentType="application/msword";
		contentDisposition="fileName=copy.png";
		String path=ServletActionContext.getRequest().getSession().getServletContext().getRealPath("")+"/file/3.png";
		try {
			inputStream=new FileInputStream(path);
			contentLength=inputStream.available();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "download";
	}
		
	
}
